Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added blank_value? to size predicate #82

Merged
merged 3 commits into from
Nov 26, 2015
Merged

Added blank_value? to size predicate #82

merged 3 commits into from
Nov 26, 2015

Conversation

hlegius
Copy link
Contributor

@hlegius hlegius commented Nov 19, 2015

This Pull Request added the ability to ignore blank values for size predicate as well occurs for other predicates i.e. presence.

The only exceptional case down to Enumerable's implementations which if defined will be treated as value as it is. i.e:

class AwesomeValidator
  include Lotus::Validations

  attribute :name, type: String, size: 8..10
  attribute :tags, type: Array,  size: 2..10
end

AwesomeValidator.new.valid? # < true
AwesomeValidator.new(name: '12345678', tags: '').valid? # < true
AwesomeValidator.new(tags: ['a', 'b']).valid? # < true
AwesomeValidator.new(name: nil).valid? # < true

AwesomeValidator.new(name: 'ooo').valid? # < false
AwesomeValidator.new(tags: []).valid? # < false
AwesomeValidator.new(name: 'abc', tags: []).valid? # < false

@solnic has argued about Conditional Validations and 'magical' validations/coercions which may introduce more complexity into this kind of issue. Maybe it worth more discussion later /cc @jodosha

Closes #81

Helio Costa e Silva added 2 commits November 19, 2015 14:58
Now, the application will ignore blank values for `size` predicate as
well occurs for other predicates i.e. presence.

The only exceptional case down to Enumerable implementations which if
defined will be treated as filled value, as in examples below:

```ruby
class AwesomeValidator
  attribute :name, type: String, size: 8..10
  attribute :tags, type: Array, size: 2..10
end

AwesomeValidator.new().valid? # < true
AwesomeValidator.new(name: '12345678', tags: '').valid? # < true
AwesomeValidator.new(tags: ['a', 'b']).valid? # < true
AwesomeValidator.new(name: nil).valid? # < true

AwesomeValidator.new(name: 'ooo').valid? # < false
AwesomeValidator.new(tags: []).valid? # < false
AwesomeValidator.new(tags: []).valid? # < false
AwesomeValidator.new(name: 'abc', tags: []).valid? # < false
```

@solnic [has argued
about](#80 (comment))
Conditional Validations and 'magical' validations/coercions
which may introduce more complexity into this kind of issue.

Closes #81

Person.new.valid? # < true
Person.new(name: '').valid? # < true
Person.new(email: '@').valid? # < true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this example valid? "@" isn't blank

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. By a mistaken, I've thought one thing and did another totally different. Good catch! Thanks 👍

@jodosha
Copy link
Member

jodosha commented Nov 26, 2015

@hlegius Thank you, merging this. 👍

jodosha added a commit that referenced this pull request Nov 26, 2015
…te-fails

Added blank_value? to size predicate
@jodosha jodosha merged commit e6b5817 into hanami:master Nov 26, 2015
@hlegius hlegius deleted the 81-blank-values-with-size-attribute-fails branch November 26, 2015 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants